package com.ruyuan2020.im.design.ChainOfResponsibilityPattern;

import com.ruyuan2020.im.design.ChainOfResponsibilityPattern.domain.Address;
import com.ruyuan2020.im.design.ChainOfResponsibilityPattern.domain.Payment;
import com.ruyuan2020.im.design.ChainOfResponsibilityPattern.domain.User;

// 订单验证类，未使用责任链模式
public class OrderValidator {
    // 验证用户身份
    private boolean validateUser(User user) {
        // 模拟验证逻辑
        return user != null && user.isAuthenticated();
    }

    // 验证支付方式
    private boolean validatePayment(Payment payment) {
        // 模拟验证逻辑
        return payment != null && payment.isAvailable();
    }

    // 验证配送地址
    private boolean validateAddress(Address address) {
        // 模拟验证逻辑
        return address != null && address.isValid();
    }

    // 提交订单方法，包含所有验证逻辑
    public String submitOrder(User user, Payment payment, Address address) {
        if (!validateUser(user)) {
            return "用户身份验证失败！";
        }
        if (!validatePayment(payment)) {
            return "支付方式验证失败！";
        }
        if (!validateAddress(address)) {
            return "配送地址验证失败！";
        }
        // 所有验证通过，处理订单
        return "订单提交成功！";
    }
}
